
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
  <meta charset="utf-8">
  <title>许龙武的技术博客</title>
  <meta name="author" content="许龙武">

  
  <meta name="description" content="我们经常会在项目中用一些NSString的Category，可以记录下来，免得每次都要查。比如NSString的URL编码、MD5加密、自适应大小等等。 方法解析 汉字转拼音 1
2
3
4
5
6
-(NSString *)transformToPinyin { NSMutableString &hellip;">
  

  <!-- http://t.co/dKP3o1e -->
  <meta name="HandheldFriendly" content="True">
  <meta name="MobileOptimized" content="320">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  
  <link rel="canonical" href="http://loongwoo.github.io/posts/2/">
  <link href="/favicon.png" rel="icon">
  <link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
  <link href="/atom.xml" rel="alternate" title="许龙武的技术博客" type="application/atom+xml">
  <script src="/javascripts/modernizr-2.0.js"></script>
  <script src="http://cdn.staticfile.org/jquery/1.9.1/jquery.min.js"></script>
  <script>!window.jQuery && document.write(unescape('%3Cscript src="/javascripts/libs/jquery.min.js"%3E%3C/script%3E'))</script>
  <script src="/javascripts/octopress.js" type="text/javascript"></script>
  

</head>

<body   >
  <header role="banner"><hgroup>
  <h1><a href="/">许龙武的技术博客</a></h1>
  
    <h2>记录所学，快乐分享</h2>
  
</hgroup>

</header>
  <nav role="navigation"><ul class="subscription" data-subscription="rss">
  <li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
  
</ul>
  
<form action="https://www.google.com/search" method="get">
  <fieldset role="search">
    <input type="hidden" name="sitesearch" value="loongwoo.github.io">
    <input class="search" type="text" name="q" results="0" placeholder="Search"/>
  </fieldset>
</form>
  
<ul class="main-navigation">
	<li><a href="/">首页</a></li>
	<li><a href="/blog/archives">所有文章</a></li>
	<li><a href="http://weibo.com/loongwoo">我的微博</a></li>
</ul>

</nav>
  <div id="main">
    <div id="content">
      <div class="blog-index">
  
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2015/07/08/at-ios-nsstringchang-yong-category/">IOS NSString常用Category</a></h1>
    
    
      <p class="meta">
        




<time class='entry-date' datetime='2015-07-08T17:34:44+08:00'><span class='date'><span class='date-month'>Jul</span> <span class='date-day'>8</span><span class='date-suffix'>th</span>, <span class='date-year'>2015</span></span> <span class='time'>5:34 pm</span></time>
        
      </p>
    
  </header>


  <div class="entry-content"><p>我们经常会在项目中用一些NSString的Category，可以记录下来，免得每次都要查。比如NSString的URL编码、MD5加密、自适应大小等等。</p>

<h2>方法解析</h2>

<h3>汉字转拼音</h3>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="bp">NSString</span> <span class="o">*</span><span class="p">)</span><span class="nf">transformToPinyin</span> <span class="p">{</span>
</span><span class='line'>    <span class="bp">NSMutableString</span> <span class="o">*</span><span class="n">mutableString</span> <span class="o">=</span> <span class="p">[</span><span class="bp">NSMutableString</span> <span class="nl">stringWithString</span><span class="p">:</span><span class="nb">self</span><span class="p">];</span>
</span><span class='line'>    <span class="n">CFStringTransform</span><span class="p">((</span><span class="n">CFMutableStringRef</span><span class="p">)</span><span class="n">mutableString</span><span class="p">,</span> <span class="nb">NULL</span><span class="p">,</span> <span class="n">kCFStringTransformToLatin</span><span class="p">,</span> <span class="nb">false</span><span class="p">);</span>
</span><span class='line'>    <span class="n">mutableString</span> <span class="o">=</span> <span class="p">(</span><span class="bp">NSMutableString</span> <span class="o">*</span><span class="p">)[</span><span class="n">mutableString</span> <span class="nl">stringByFoldingWithOptions</span><span class="p">:</span><span class="n">NSDiacriticInsensitiveSearch</span> <span class="nl">locale</span><span class="p">:[</span><span class="bp">NSLocale</span> <span class="n">currentLocale</span><span class="p">]];</span>
</span><span class='line'>    <span class="k">return</span> <span class="n">mutableString</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>尽管对汉字的排序可以用<code>- (NSComparisonResult)localizedCompare:(NSString *)string;</code>进行排序，但也有时候需要手动排序，这个拓展就有用了。</p>

<h3>URL编码</h3>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="bp">NSString</span> <span class="o">*</span><span class="p">)</span><span class="nf">URLEncodedString</span><span class="p">{</span>
</span><span class='line'>    <span class="bp">NSString</span> <span class="o">*</span><span class="n">encodedString</span> <span class="o">=</span> <span class="p">(</span><span class="bp">NSString</span> <span class="o">*</span><span class="p">)</span><span class="n">CFBridgingRelease</span><span class="p">(</span><span class="n">CFURLCreateStringByAddingPercentEscapes</span><span class="p">(</span><span class="n">kCFAllocatorDefault</span><span class="p">,</span>
</span><span class='line'>        <span class="p">(</span><span class="n">CFStringRef</span><span class="p">)</span><span class="nb">self</span><span class="p">,</span>
</span><span class='line'>        <span class="p">(</span><span class="n">CFStringRef</span><span class="p">)</span><span class="s">@&quot;!$&amp;&#39;()*+,-./:;=?@_~%#[]&quot;</span><span class="p">,</span>
</span><span class='line'>        <span class="nb">NULL</span><span class="p">,</span>
</span><span class='line'>        <span class="n">kCFStringEncodingUTF8</span><span class="p">));</span>
</span><span class='line'>    <span class="k">return</span> <span class="n">encodedString</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>对于包含中文的URL不能整体转化为UTF-8的格式，那么就可以用<code>CFURLCreateStringByAddingPercentEscapes</code>来排除掉一些应该保留的字符。</p>

<h3>Json字符串转化为Object</h3>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="kt">id</span><span class="p">)</span><span class="nf">JSONObject</span><span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="p">[</span><span class="bp">NSJSONSerialization</span> <span class="nl">JSONObjectWithData</span><span class="p">:[</span><span class="nb">self</span> <span class="nl">dataUsingEncoding</span><span class="p">:</span><span class="n">NSUTF8StringEncoding</span><span class="p">]</span> <span class="nl">options</span><span class="p">:</span><span class="n">kNilOptions</span> <span class="nl">error</span><span class="p">:</span><span class="nb">nil</span><span class="p">];</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>网络接口很多是Json的字符串，该方法直接转化为NSArray、NSDictionary等。</p>

<h3>MD5加密</h3>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="bp">NSString</span><span class="o">*</span><span class="p">)</span><span class="nf">md5</span><span class="p">{</span>
</span><span class='line'>    <span class="k">const</span> <span class="kt">char</span> <span class="o">*</span><span class="n">cStr</span> <span class="o">=</span> <span class="p">[</span><span class="nb">self</span> <span class="n">UTF8String</span><span class="p">];</span>
</span><span class='line'>    <span class="kt">unsigned</span> <span class="kt">char</span> <span class="n">result</span><span class="p">[</span><span class="n">CC_MD5_DIGEST_LENGTH</span><span class="p">];</span>
</span><span class='line'>    <span class="n">CC_MD5</span><span class="p">(</span> <span class="n">cStr</span><span class="p">,</span> <span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="n">strlen</span><span class="p">(</span><span class="n">cStr</span><span class="p">),</span> <span class="n">result</span> <span class="p">);</span>
</span><span class='line'>    <span class="k">return</span> <span class="p">[</span><span class="bp">NSString</span> <span class="nl">stringWithFormat</span><span class="p">:</span> <span class="s">@&quot;%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X&quot;</span><span class="p">,</span> <span class="n">result</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">4</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">5</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">6</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">7</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">8</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">9</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">10</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">11</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">12</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">13</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">14</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">15</span><span class="p">]];</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>MD5加密也是常用的方法，记得导入<code>#import &lt;CommonCrypto/CommonDigest.h&gt;</code>。</p>

<h3>UTF16的MD5加密</h3>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="bp">NSString</span> <span class="o">*</span><span class="p">)</span><span class="nf">md5ForUTF16</span><span class="p">{</span>
</span><span class='line'>    <span class="bp">NSData</span> <span class="o">*</span><span class="n">temp</span> <span class="o">=</span> <span class="p">[</span><span class="nb">self</span> <span class="nl">dataUsingEncoding</span><span class="p">:</span><span class="n">NSUTF16LittleEndianStringEncoding</span><span class="p">];</span>
</span><span class='line'>    <span class="kt">UInt8</span> <span class="o">*</span><span class="n">cStr</span> <span class="o">=</span> <span class="p">(</span><span class="kt">UInt8</span> <span class="o">*</span><span class="p">)[</span><span class="n">temp</span> <span class="n">bytes</span><span class="p">];</span>
</span><span class='line'>    <span class="kt">unsigned</span> <span class="kt">char</span> <span class="n">result</span><span class="p">[</span><span class="n">CC_MD5_DIGEST_LENGTH</span><span class="p">];</span>
</span><span class='line'>    <span class="n">CC_MD5</span><span class="p">(</span><span class="n">cStr</span><span class="p">,</span> <span class="p">(</span><span class="kt">int</span><span class="p">)[</span><span class="n">temp</span> <span class="n">length</span><span class="p">],</span> <span class="n">result</span><span class="p">);</span>
</span><span class='line'>    <span class="k">return</span> <span class="p">[</span><span class="bp">NSString</span> <span class="nl">stringWithFormat</span><span class="p">:</span><span class="s">@&quot;%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x&quot;</span><span class="p">,</span> <span class="n">result</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">4</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">5</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">6</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">7</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">8</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">9</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">10</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">11</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">12</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">13</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">14</span><span class="p">],</span> <span class="n">result</span><span class="p">[</span><span class="mi">15</span><span class="p">]];</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>这个加密倒不是很常用，经常有前面一个就够用了，这里统一记录一下。</p>

<h3>去掉前后的空格</h3>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="bp">NSString</span> <span class="o">*</span><span class="p">)</span><span class="nf">trim</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="p">[</span><span class="nb">self</span> <span class="nl">stringByTrimmingCharactersInSet</span><span class="p">:[</span><span class="bp">NSCharacterSet</span> <span class="n">whitespaceAndNewlineCharacterSet</span><span class="p">]];</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>记得在写C#的时候，经常要带着trim函数走。但是IOS里面用的地方不多，记得用过的就是URL的参数，以及在要把输入内容转化为数字的时候。在输入结束的时候trim一下是个应该坚持的习惯。</p>

<h3>去掉行中多余空格</h3>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="bp">NSString</span> <span class="o">*</span><span class="p">)</span><span class="nf">trimTheExtraSpaces</span><span class="p">{</span>
</span><span class='line'>    <span class="bp">NSCharacterSet</span> <span class="o">*</span><span class="n">whitespaces</span> <span class="o">=</span> <span class="p">[</span><span class="bp">NSCharacterSet</span> <span class="n">whitespaceCharacterSet</span><span class="p">];</span>
</span><span class='line'>    <span class="bp">NSPredicate</span> <span class="o">*</span><span class="n">noEmptyStrings</span> <span class="o">=</span> <span class="p">[</span><span class="bp">NSPredicate</span> <span class="nl">predicateWithFormat</span><span class="p">:</span><span class="s">@&quot;SELF != &#39;&#39;&quot;</span><span class="p">];</span>
</span><span class='line'>    <span class="bp">NSArray</span> <span class="o">*</span><span class="n">parts</span> <span class="o">=</span> <span class="p">[</span><span class="nb">self</span> <span class="nl">componentsSeparatedByCharactersInSet</span><span class="p">:</span><span class="n">whitespaces</span><span class="p">];</span>
</span><span class='line'>    <span class="bp">NSArray</span> <span class="o">*</span><span class="n">filteredArray</span> <span class="o">=</span> <span class="p">[</span><span class="n">parts</span> <span class="nl">filteredArrayUsingPredicate</span><span class="p">:</span><span class="n">noEmptyStrings</span><span class="p">];</span>
</span><span class='line'>    <span class="k">return</span> <span class="p">[</span><span class="n">filteredArray</span> <span class="nl">componentsJoinedByString</span><span class="p">:</span><span class="s">@&quot; &quot;</span><span class="p">];</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>该方法会去掉string中的多余空格，有多个的话留一个。</p>

<h3>是否是空字符</h3>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="kt">BOOL</span><span class="p">)</span><span class="nf">isEmpty</span> <span class="p">{</span>
</span><span class='line'>    <span class="bp">NSCharacterSet</span> <span class="o">*</span><span class="n">charSet</span> <span class="o">=</span> <span class="p">[</span><span class="bp">NSCharacterSet</span> <span class="n">whitespaceAndNewlineCharacterSet</span><span class="p">];</span>
</span><span class='line'>    <span class="bp">NSString</span> <span class="o">*</span><span class="n">trimmed</span> <span class="o">=</span> <span class="p">[</span><span class="nb">self</span> <span class="nl">stringByTrimmingCharactersInSet</span><span class="p">:</span><span class="n">charSet</span><span class="p">];</span>
</span><span class='line'>    <span class="k">return</span> <span class="p">[</span><span class="n">trimmed</span> <span class="nl">isEqualToString</span><span class="p">:</span><span class="s">@&quot;&quot;</span><span class="p">];</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>我们常常用<code>if( nil == tempStr || 0 == tempStr.lenth ){...}</code>来判断是否为空。但比如<code>NSString \*tmp4=@"   ";</code>这样一个字符串，<code>[tmp4 length]</code>求的长度为3。但是用上面的方法可以看到是空的。</p>

<h3>自适应大小</h3>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="bp">CGSize</span><span class="p">)</span><span class="nf">sizeWithFont:</span><span class="p">(</span><span class="bp">UIFont</span> <span class="o">*</span><span class="p">)</span><span class="nv">font</span>
</span><span class='line'>    <span class="nf">constrainedToSize:</span><span class="p">(</span><span class="bp">CGSize</span><span class="p">)</span><span class="nv">constrainedSize</span>
</span><span class='line'>            <span class="nf">lineBreakMode:</span><span class="p">(</span><span class="n">NSLineBreakMode</span><span class="p">)</span><span class="nv">lineBreakMode</span> <span class="p">{</span>
</span><span class='line'>    <span class="k">if</span> <span class="p">([</span><span class="nb">self</span> <span class="nl">respondsToSelector</span><span class="p">:</span><span class="k">@selector</span><span class="p">(</span><span class="nl">boundingRectWithSize</span><span class="p">:</span><span class="nl">options</span><span class="p">:</span><span class="nl">attributes</span><span class="p">:</span><span class="nl">context</span><span class="p">:)])</span> <span class="p">{</span>
</span><span class='line'>        <span class="bp">NSMutableParagraphStyle</span> <span class="o">*</span><span class="n">paragraphStyle</span> <span class="o">=</span> <span class="p">[[</span><span class="bp">NSMutableParagraphStyle</span> <span class="n">alloc</span><span class="p">]</span> <span class="n">init</span><span class="p">];</span>
</span><span class='line'>        <span class="n">paragraphStyle</span><span class="p">.</span><span class="n">lineBreakMode</span> <span class="o">=</span> <span class="n">lineBreakMode</span><span class="p">;</span>
</span><span class='line'>        <span class="bp">NSDictionary</span> <span class="o">*</span><span class="n">attributes</span> <span class="o">=</span> <span class="l">@{</span><span class="nl">NSFontAttributeName</span><span class="p">:</span><span class="n">font</span><span class="p">,</span> <span class="nl">NSParagraphStyleAttributeName</span><span class="p">:</span><span class="n">paragraphStyle</span><span class="l">}</span><span class="p">;</span>
</span><span class='line'>        <span class="bp">CGRect</span> <span class="n">boundingRect</span> <span class="o">=</span> <span class="p">[</span><span class="nb">self</span> <span class="nl">boundingRectWithSize</span><span class="p">:</span><span class="n">constrainedSize</span> <span class="nl">options</span><span class="p">:</span><span class="n">NSStringDrawingUsesLineFragmentOrigin</span>  <span class="nl">attributes</span><span class="p">:</span><span class="n">attributes</span> <span class="nl">context</span><span class="p">:</span><span class="nb">nil</span><span class="p">];</span>
</span><span class='line'>    <span class="k">return</span> <span class="n">CGSizeMake</span><span class="p">(</span><span class="n">ceilf</span><span class="p">(</span><span class="n">boundingRect</span><span class="p">.</span><span class="n">size</span><span class="p">.</span><span class="n">width</span><span class="p">),</span> <span class="n">ceilf</span><span class="p">(</span><span class="n">boundingRect</span><span class="p">.</span><span class="n">size</span><span class="p">.</span><span class="n">height</span><span class="p">));</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'><span class="cp">#pragma clang diagnostic push</span>
</span><span class='line'><span class="cp">#pragma clang diagnostic ignored &quot;-Wdeprecated-declarations&quot;</span>
</span><span class='line'>    <span class="k">return</span> <span class="p">[</span><span class="nb">self</span> <span class="nl">sizeWithFont</span><span class="p">:</span><span class="n">font</span> <span class="nl">constrainedToSize</span><span class="p">:</span><span class="n">constrainedSize</span> <span class="nl">lineBreakMode</span><span class="p">:</span><span class="n">lineBreakMode</span><span class="p">];</span>
</span><span class='line'><span class="cp">#pragma clang diagnostic pop</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>这个就再熟悉不过了，不过定义Category的时候要记得导入<code>#import &lt;UIKit/UIKit.h&gt;</code>，否则CGSize这些会报错。还有一个用法</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="cp">#pragma clang diagnostic push</span>
</span><span class='line'><span class="cp">#pragma clang diagnostic ignored &quot;-相关命令&quot;</span>
</span><span class='line'><span class="c1">// 你自己的代码</span>
</span><span class='line'><span class="cp">#pragma clang diagnostic pop</span>
</span></code></pre></td></tr></table></div></figure>


<p>#pragma我们常用来做分段注释，还有一个功能是处理编译器警告。<code>-Wdeprecated-declarations</code>表示方法弃用。加了这个之后，就不会再出现黄色警告了。<br/>
其他的情况可以查询<a href="http://fuckingclangwarnings.com">Which Clang Warning Is Generating This Message?</a></p>

<h2>源码下载</h2>

<p><a href="https://github.com/Loongwoo/StringExtensionDemo">StringExtensionDemo</a></p>

<p>在项目中导入NSString+Extensions.h和NSString+Extensions.m即可。</p>
</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2015/07/07/at-ios-pdfxian-shi-he-liu-lan/">IOS PDF显示和浏览</a></h1>
    
    
      <p class="meta">
        




<time class='entry-date' datetime='2015-07-07T11:04:31+08:00'><span class='date'><span class='date-month'>Jul</span> <span class='date-day'>7</span><span class='date-suffix'>th</span>, <span class='date-year'>2015</span></span> <span class='time'>11:04 am</span></time>
        
      </p>
    
  </header>


  <div class="entry-content"><h2>简介</h2>

<p>这里介绍两种方法显示PDF，第一种用UIWebView，特点是代码简单，但是没法实现翻页效果。第二中方法利用IOS系统的CGContextDrawPDFPage方法手动实现，代码复杂一些，同时需要配合UIScrollView实现缩放，以及利用UIPageViewController实现翻页的效果。</p>

<h2>方法一：利用UIWebView</h2>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="kt">void</span><span class="p">)</span><span class="nf">loadPDF:</span><span class="p">(</span><span class="bp">NSString</span><span class="o">*</span><span class="p">)</span><span class="nv">fileName</span> <span class="nf">inWebView:</span><span class="p">(</span><span class="bp">UIWebView</span><span class="o">*</span><span class="p">)</span><span class="nv">webView</span><span class="p">{</span>
</span><span class='line'>    <span class="bp">NSString</span> <span class="o">*</span><span class="n">path</span> <span class="o">=</span> <span class="p">[[</span><span class="bp">NSBundle</span> <span class="n">mainBundle</span><span class="p">]</span> <span class="nl">pathForResource</span><span class="p">:</span><span class="n">fileName</span> <span class="nl">ofType</span><span class="p">:</span><span class="nb">nil</span><span class="p">];</span>
</span><span class='line'>    <span class="bp">NSURL</span> <span class="o">*</span><span class="n">url</span> <span class="o">=</span> <span class="p">[</span><span class="bp">NSURL</span> <span class="nl">fileURLWithPath</span><span class="p">:</span><span class="n">path</span><span class="p">];</span>
</span><span class='line'>    <span class="bp">NSURLRequest</span> <span class="o">*</span><span class="n">request</span> <span class="o">=</span> <span class="p">[</span><span class="bp">NSURLRequest</span> <span class="nl">requestWithURL</span><span class="p">:</span><span class="n">url</span><span class="p">];</span>
</span><span class='line'>    <span class="p">[</span><span class="n">webView</span> <span class="nl">loadRequest</span><span class="p">:</span><span class="n">request</span><span class="p">];</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<ul>
<li>技巧：设置<code>webView.scalesPageToFit = YES;</code>可以实现pinch放大缩小</li>
<li>缺点：没有翻页的动画效果</li>
</ul>


<h2>方法二：利用CGContextDrawPDFPage</h2>

<h3>CGContextDrawPDFPage</h3>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="kt">void</span><span class="p">)</span><span class="nf">drawInContext:</span><span class="p">(</span><span class="n">CGContextRef</span><span class="p">)</span><span class="nv">context</span> <span class="nf">atPageNo:</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span><span class="nv">page_no</span><span class="p">{</span>
</span><span class='line'>    <span class="c1">// PDF page drawing expects a Lower-Left coordinate system, so we flip the coordinate system</span>
</span><span class='line'>    <span class="c1">// before we start drawing.</span>
</span><span class='line'>    <span class="n">CGContextTranslateCTM</span><span class="p">(</span><span class="n">context</span><span class="p">,</span> <span class="mf">0.0</span><span class="p">,</span> <span class="nb">self</span><span class="p">.</span><span class="n">bounds</span><span class="p">.</span><span class="n">size</span><span class="p">.</span><span class="n">height</span><span class="p">);</span>
</span><span class='line'>    <span class="n">CGContextScaleCTM</span><span class="p">(</span><span class="n">context</span><span class="p">,</span> <span class="mf">1.0</span><span class="p">,</span> <span class="o">-</span><span class="mf">1.0</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>    <span class="k">if</span> <span class="p">(</span><span class="n">pageNO</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>        <span class="n">pageNO</span> <span class="o">=</span> <span class="mi">1</span><span class="p">;</span>
</span><span class='line'>    <span class="p">}</span>
</span><span class='line'>    <span class="n">CGPDFPageRef</span> <span class="n">page</span> <span class="o">=</span> <span class="n">CGPDFDocumentGetPage</span><span class="p">(</span><span class="n">pdfDocument</span><span class="p">,</span> <span class="n">pageNO</span><span class="p">);</span>
</span><span class='line'>    <span class="n">CGContextSaveGState</span><span class="p">(</span><span class="n">context</span><span class="p">);</span>
</span><span class='line'>    <span class="p">{</span>
</span><span class='line'>        <span class="bp">CGAffineTransform</span> <span class="n">pdfTransform</span> <span class="o">=</span> <span class="n">CGPDFPageGetDrawingTransform</span><span class="p">(</span><span class="n">page</span><span class="p">,</span> <span class="n">kCGPDFCropBox</span><span class="p">,</span> <span class="nb">self</span><span class="p">.</span><span class="n">bounds</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nb">true</span><span class="p">);</span>
</span><span class='line'>        <span class="n">CGContextConcatCTM</span><span class="p">(</span><span class="n">context</span><span class="p">,</span> <span class="n">pdfTransform</span><span class="p">);</span>
</span><span class='line'>        <span class="n">CGContextDrawPDFPage</span><span class="p">(</span><span class="n">context</span><span class="p">,</span> <span class="n">page</span><span class="p">);</span>
</span><span class='line'>    <span class="p">}</span>
</span><span class='line'>    <span class="n">CGContextRestoreGState</span><span class="p">(</span><span class="n">context</span><span class="p">);</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>需要先反转坐标，根据pageNO获取到CGPDFDocumentRef的那一页，直接CGContextDrawPDFPage。</p>

<h3>UIScrollView</h3>

<p>配合UIScrollView实现缩放，ZPDFPageController的主要代码：</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="kt">void</span><span class="p">)</span><span class="nf">viewDidLoad</span><span class="p">{</span>
</span><span class='line'>    <span class="p">[</span><span class="nb">super</span> <span class="n">viewDidLoad</span><span class="p">];</span>
</span><span class='line'>    <span class="bp">UIScrollView</span> <span class="o">*</span><span class="n">scrollView</span> <span class="o">=</span> <span class="p">[[</span><span class="bp">UIScrollView</span> <span class="n">alloc</span><span class="p">]</span> <span class="nl">initWithFrame</span><span class="p">:</span><span class="nb">self</span><span class="p">.</span><span class="n">view</span><span class="p">.</span><span class="n">bounds</span><span class="p">];</span>
</span><span class='line'>    <span class="n">scrollView</span><span class="p">.</span><span class="n">showsVerticalScrollIndicator</span><span class="o">=</span><span class="nb">NO</span><span class="p">;</span>
</span><span class='line'>    <span class="n">scrollView</span><span class="p">.</span><span class="n">showsHorizontalScrollIndicator</span><span class="o">=</span><span class="nb">NO</span><span class="p">;</span>
</span><span class='line'>    <span class="n">scrollView</span><span class="p">.</span><span class="n">minimumZoomScale</span><span class="o">=</span><span class="mf">1.0f</span><span class="p">;</span>
</span><span class='line'>    <span class="n">scrollView</span><span class="p">.</span><span class="n">maximumZoomScale</span><span class="o">=</span><span class="mf">3.0f</span><span class="p">;</span>
</span><span class='line'>    <span class="n">scrollView</span><span class="p">.</span><span class="n">delegate</span><span class="o">=</span><span class="nb">self</span><span class="p">;</span>
</span><span class='line'>    <span class="p">[</span><span class="nb">self</span><span class="p">.</span><span class="n">view</span> <span class="nl">addSubview</span><span class="p">:</span><span class="n">scrollView</span><span class="p">];</span>
</span><span class='line'>
</span><span class='line'>    <span class="n">pdfView</span> <span class="o">=</span> <span class="p">[[</span><span class="n">ZPDFView</span> <span class="n">alloc</span><span class="p">]</span> <span class="nl">initWithFrame</span><span class="p">:</span><span class="n">scrollView</span><span class="p">.</span><span class="n">bounds</span> <span class="nl">atPage</span><span class="p">:(</span><span class="kt">int</span><span class="p">)</span><span class="nb">self</span><span class="p">.</span><span class="n">pageNO</span> <span class="nl">withPDFDoc</span><span class="p">:</span><span class="nb">self</span><span class="p">.</span><span class="n">pdfDocument</span><span class="p">];</span>
</span><span class='line'>    <span class="n">pdfView</span><span class="p">.</span><span class="n">backgroundColor</span><span class="o">=</span><span class="p">[</span><span class="bp">UIColor</span> <span class="n">whiteColor</span><span class="p">];</span>
</span><span class='line'>    <span class="p">[</span><span class="n">scrollView</span> <span class="nl">addSubview</span><span class="p">:</span><span class="n">pdfView</span><span class="p">];</span>
</span><span class='line'>
</span><span class='line'>    <span class="n">scrollView</span><span class="p">.</span><span class="n">contentSize</span><span class="o">=</span><span class="n">pdfView</span><span class="p">.</span><span class="n">bounds</span><span class="p">.</span><span class="n">size</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="p">-</span> <span class="p">(</span><span class="bp">UIView</span> <span class="o">*</span><span class="p">)</span><span class="nf">viewForZoomingInScrollView:</span><span class="p">(</span><span class="bp">UIScrollView</span> <span class="o">*</span><span class="p">)</span><span class="nv">scrollView</span><span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="n">pdfView</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<h3>UIPageViewController</h3>

<p>UIPageViewController的TransitionStyle设置为UIPageViewControllerTransitionStylePageCurl（翻页）。其次也是构建UIPageViewControllerDataSource中的两个方法（ZPDFPageModel）。要注意他们返回的是UIViewController，具体实现请参考源码。</p>

<h2>效果展示</h2>

<p><img src="/images/pdf1.png" alt="PDF1" /> <img src="/images/pdf2.png" alt="PDF2" /></p>

<h2>源码下载</h2>

<p><a href="https://github.com/Loongwoo/PDFDemo">PDFDemo</a></p>

<h2>参考链接</h2>

<p><a href="http://blog.csdn.net/yiyaaixuexi/article/details/7645725">http://blog.csdn.net/yiyaaixuexi/article/details/7645725</a></p>
</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2015/07/07/at-ios-appqi-dong-yin-dao-jie-mian/">IOS App启动引导界面</a></h1>
    
    
      <p class="meta">
        




<time class='entry-date' datetime='2015-07-07T01:49:19+08:00'><span class='date'><span class='date-month'>Jul</span> <span class='date-day'>7</span><span class='date-suffix'>th</span>, <span class='date-year'>2015</span></span> <span class='time'>1:49 am</span></time>
        
      </p>
    
  </header>


  <div class="entry-content"><h2>前言</h2>

<p>由于之前一直都是用纯代码构建页面，一直没有学习怎么用storyboard。已经深深的感受到了纯代码写页面的繁琐了。所以这个Demo不但学习怎么用PageViewController实现启动引导的图片展示，也初步学习了怎么用storyboard构建页面。</p>

<h2>构建storyboard</h2>

<p>先创建一个Single View Application，构建Main.storyboard，预览如下
<img src="/images/storyboard.png" alt="预览" />
除了最左的View Controller（根VC），新增了两个分别是右上Page View Controller和右下View Controller（内容VC）。</p>

<ol>
<li>确保勾选Use Auto Layout和Use Size Classes</li>
<li>关于Size Classes的讲解请参考<a href="http://www.cocoachina.com/ios/20141217/10669.html">链接1</a>，此处为了适配所有的设备，故选择了默认的w Any h Any</li>
<li>为内容VC添加一个Label和UIImageView，分别设置Constraints<br/>
鼠标右键点击Label拖动，在提示框选择Top Space to Top Layout Guide（IOS7中会自动向下移动20个像素）和Center Horizontally In Container（水平居中）。点击右边Edit可以设置具体的值。
<img src="/images/labelSC.png" alt="设置Label的约束" />
如下设置上下左右约束，Trailing Space to: superview（右）为-16；Leading Space to: superview（左）为-16；Top Space to: Label（上）为10，Button Space to: Bottom Layout Guide（下）为0；
<img src="/images/imageviewSC.png" alt="设置imageView的界限" /></li>
<li>为根VC添加一个Button，也设置好Constraints</li>
</ol>


<h2>代码实现</h2>

<h3>创建PageContentViewController</h3>

<p>连接内容VC和PageContentViewController.h，再连接好titleLabel和backgroundImageView，最后申明如下三个属性：</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="k">@property</span> <span class="p">(</span><span class="k">weak</span><span class="p">,</span> <span class="k">nonatomic</span><span class="p">)</span> <span class="kt">IBOutlet</span> <span class="bp">UILabel</span> <span class="o">*</span><span class="n">titleLabel</span><span class="p">;</span>
</span><span class='line'><span class="k">@property</span> <span class="p">(</span><span class="k">weak</span><span class="p">,</span> <span class="k">nonatomic</span><span class="p">)</span> <span class="kt">IBOutlet</span> <span class="bp">UIImageView</span> <span class="o">*</span><span class="n">backgroundImageView</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'><span class="k">@property</span><span class="p">(</span><span class="k">assign</span><span class="p">,</span> <span class="k">nonatomic</span><span class="p">)</span> <span class="bp">NSUInteger</span> <span class="n">pageIndex</span><span class="p">;</span>
</span><span class='line'><span class="k">@property</span><span class="p">(</span><span class="k">copy</span><span class="p">,</span> <span class="k">nonatomic</span><span class="p">)</span> <span class="bp">NSString</span> <span class="o">*</span><span class="n">titleText</span><span class="p">;</span>
</span><span class='line'><span class="k">@property</span><span class="p">(</span><span class="k">copy</span><span class="p">,</span> <span class="k">nonatomic</span><span class="p">)</span> <span class="bp">NSString</span> <span class="o">*</span><span class="n">imageFile</span><span class="p">;</span>
</span></code></pre></td></tr></table></div></figure>


<p>PageContentViewController.m, 在viewDidLoad中添加</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="nb">self</span><span class="p">.</span><span class="n">titleLabel</span><span class="p">.</span><span class="n">text</span><span class="o">=</span><span class="nb">self</span><span class="p">.</span><span class="n">titleText</span><span class="p">;</span>
</span><span class='line'><span class="nb">self</span><span class="p">.</span><span class="n">backgroundImageView</span><span class="p">.</span><span class="n">image</span><span class="o">=</span><span class="p">[</span><span class="bp">UIImage</span> <span class="nl">imageNamed</span><span class="p">:</span><span class="nb">self</span><span class="p">.</span><span class="n">imageFile</span><span class="p">];</span>
</span></code></pre></td></tr></table></div></figure>


<h3>ViewController</h3>

<p>ViewController.h中申请UIPageViewControllerDataSource，连接startBtn</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="k">@interface</span> <span class="nc">ViewController</span> : <span class="bp">UIViewController</span><span class="o">&lt;</span><span class="bp">UIPageViewControllerDataSource</span><span class="o">&gt;</span>
</span><span class='line'>
</span><span class='line'><span class="o">-</span><span class="p">(</span><span class="kt">IBAction</span><span class="p">)</span><span class="nl">startWalkthrough</span><span class="p">:(</span><span class="kt">id</span><span class="p">)</span><span class="n">sender</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'><span class="k">@property</span> <span class="p">(</span><span class="k">strong</span><span class="p">,</span> <span class="k">nonatomic</span><span class="p">)</span> <span class="bp">UIPageViewController</span> <span class="o">*</span><span class="n">pageViewController</span><span class="p">;</span>
</span><span class='line'><span class="k">@property</span> <span class="p">(</span><span class="k">strong</span><span class="p">,</span> <span class="k">nonatomic</span><span class="p">)</span> <span class="bp">NSArray</span> <span class="o">*</span><span class="n">pageTitles</span><span class="p">;</span>
</span><span class='line'><span class="k">@property</span> <span class="p">(</span><span class="k">strong</span><span class="p">,</span> <span class="k">nonatomic</span><span class="p">)</span> <span class="bp">NSArray</span> <span class="o">*</span><span class="n">pageImages</span><span class="p">;</span>
</span><span class='line'><span class="k">@end</span>
</span></code></pre></td></tr></table></div></figure>


<p>ViewController.m, 实现UIPageViewControllerDateSource的四个方法</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="cp">#pragma mark - Page View Controller Data Source</span>
</span><span class='line'>
</span><span class='line'><span class="p">-(</span><span class="bp">UIViewController</span> <span class="o">*</span><span class="p">)</span><span class="nf">pageViewController:</span><span class="p">(</span><span class="bp">UIPageViewController</span> <span class="o">*</span><span class="p">)</span><span class="nv">pageViewController</span> <span class="nf">viewControllerBeforeViewController:</span><span class="p">(</span><span class="bp">UIViewController</span> <span class="o">*</span><span class="p">)</span><span class="nv">viewController</span><span class="p">{</span>
</span><span class='line'>    <span class="bp">NSUInteger</span> <span class="n">index</span> <span class="o">=</span> <span class="p">((</span><span class="n">PageContentViewController</span><span class="o">*</span><span class="p">)</span> <span class="n">viewController</span><span class="p">).</span><span class="n">pageIndex</span><span class="p">;</span>
</span><span class='line'>    <span class="k">if</span> <span class="p">((</span><span class="n">index</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="o">||</span> <span class="p">(</span><span class="n">index</span> <span class="o">==</span> <span class="n">NSNotFound</span><span class="p">))</span> <span class="p">{</span>
</span><span class='line'>        <span class="k">return</span> <span class="nb">nil</span><span class="p">;</span>
</span><span class='line'>    <span class="p">}</span>
</span><span class='line'>    <span class="n">index</span><span class="o">--</span><span class="p">;</span>
</span><span class='line'>    <span class="k">return</span> <span class="p">[</span><span class="nb">self</span> <span class="nl">viewControllerAtIndex</span><span class="p">:</span><span class="n">index</span><span class="p">];</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="p">-(</span><span class="bp">UIViewController</span> <span class="o">*</span><span class="p">)</span><span class="nf">pageViewController:</span><span class="p">(</span><span class="bp">UIPageViewController</span> <span class="o">*</span><span class="p">)</span><span class="nv">pageViewController</span> <span class="nf">viewControllerAfterViewController:</span><span class="p">(</span><span class="bp">UIViewController</span> <span class="o">*</span><span class="p">)</span><span class="nv">viewController</span><span class="p">{</span>
</span><span class='line'>    <span class="bp">NSUInteger</span> <span class="n">index</span> <span class="o">=</span> <span class="p">((</span><span class="n">PageContentViewController</span><span class="o">*</span><span class="p">)</span> <span class="n">viewController</span><span class="p">).</span><span class="n">pageIndex</span><span class="p">;</span>         
</span><span class='line'>    <span class="k">if</span> <span class="p">(</span><span class="n">index</span> <span class="o">==</span> <span class="n">NSNotFound</span><span class="p">)</span> <span class="p">{</span>
</span><span class='line'>        <span class="k">return</span> <span class="nb">nil</span><span class="p">;</span>
</span><span class='line'>    <span class="p">}</span>              
</span><span class='line'>    <span class="n">index</span><span class="o">++</span><span class="p">;</span>
</span><span class='line'>    <span class="k">if</span> <span class="p">(</span><span class="n">index</span> <span class="o">==</span> <span class="p">[</span><span class="nb">self</span><span class="p">.</span><span class="n">pageTitles</span> <span class="n">count</span><span class="p">])</span> <span class="p">{</span>
</span><span class='line'>        <span class="k">return</span> <span class="nb">nil</span><span class="p">;</span>
</span><span class='line'>    <span class="p">}</span>
</span><span class='line'>    <span class="k">return</span> <span class="p">[</span><span class="nb">self</span> <span class="nl">viewControllerAtIndex</span><span class="p">:</span><span class="n">index</span><span class="p">];</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="p">-(</span><span class="bp">NSInteger</span><span class="p">)</span><span class="nf">presentationCountForPageViewController:</span><span class="p">(</span><span class="bp">UIPageViewController</span> <span class="o">*</span><span class="p">)</span><span class="nv">pageViewController</span><span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="p">[</span><span class="nb">self</span><span class="p">.</span><span class="n">pageTitles</span> <span class="n">count</span><span class="p">];</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'>
</span><span class='line'><span class="p">-(</span><span class="bp">NSInteger</span><span class="p">)</span><span class="nf">presentationIndexForPageViewController:</span><span class="p">(</span><span class="bp">UIPageViewController</span> <span class="o">*</span><span class="p">)</span><span class="nv">pageViewController</span><span class="p">{</span>
</span><span class='line'>    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>前面两个方法告诉PageViewController前一页或者后一页的显示内容；后两个方法告诉页面指示器（Page Indicator）的总页数和初始位置，当然只有在UIPageViewController的TransitionStyle为UIPageViewControllerTransitionStyleScroll的时候才有效。</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="n">PageContentViewController</span> <span class="o">*</span><span class="p">)</span><span class="nf">viewControllerAtIndex:</span><span class="p">(</span><span class="bp">NSUInteger</span><span class="p">)</span><span class="nv">index</span><span class="p">{</span>
</span><span class='line'>    <span class="k">if</span> <span class="p">(([</span><span class="nb">self</span><span class="p">.</span><span class="n">pageTitles</span> <span class="n">count</span><span class="p">]</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="o">||</span> <span class="p">(</span><span class="n">index</span> <span class="o">&gt;=</span> <span class="p">[</span><span class="nb">self</span><span class="p">.</span><span class="n">pageTitles</span> <span class="n">count</span><span class="p">]))</span> <span class="p">{</span>
</span><span class='line'>        <span class="k">return</span> <span class="nb">nil</span><span class="p">;</span>
</span><span class='line'>    <span class="p">}</span>
</span><span class='line'>    <span class="c1">// Create a new view controller and pass suitable data.</span>
</span><span class='line'>    <span class="n">PageContentViewController</span> <span class="o">*</span><span class="n">pageContentViewController</span> <span class="o">=</span> <span class="p">[</span><span class="nb">self</span><span class="p">.</span><span class="n">storyboard</span> <span class="nl">instantiateViewControllerWithIdentifier</span><span class="p">:</span><span class="s">@&quot;PageContentViewController&quot;</span><span class="p">];</span>
</span><span class='line'>    <span class="n">pageContentViewController</span><span class="p">.</span><span class="n">imageFile</span> <span class="o">=</span> <span class="nb">self</span><span class="p">.</span><span class="n">pageImages</span><span class="p">[</span><span class="n">index</span><span class="p">];</span>
</span><span class='line'>    <span class="n">pageContentViewController</span><span class="p">.</span><span class="n">titleText</span> <span class="o">=</span> <span class="nb">self</span><span class="p">.</span><span class="n">pageTitles</span><span class="p">[</span><span class="n">index</span><span class="p">];</span>
</span><span class='line'>    <span class="n">pageContentViewController</span><span class="p">.</span><span class="n">pageIndex</span> <span class="o">=</span> <span class="n">index</span><span class="p">;</span>
</span><span class='line'>    <span class="k">return</span> <span class="n">pageContentViewController</span><span class="p">;</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<p>该方法根据位置信息返回内容页面。</p>

<p>最后实现ViewDidLoad</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">-(</span><span class="kt">void</span><span class="p">)</span><span class="nf">viewDidLoad</span><span class="p">{</span>
</span><span class='line'>    <span class="p">[</span><span class="nb">super</span> <span class="n">viewDidLoad</span><span class="p">];</span>
</span><span class='line'>    <span class="n">_pageTitles</span> <span class="o">=</span> <span class="l">@[</span> <span class="s">@&quot;帆船&quot;</span><span class="p">,</span> <span class="s">@&quot;美女&quot;</span><span class="p">,</span> <span class="s">@&quot;豪车&quot;</span><span class="p">,</span>  <span class="s">@&quot;碧海蓝天&quot;</span><span class="l">]</span><span class="p">;</span>
</span><span class='line'>    <span class="n">_pageImages</span> <span class="o">=</span> <span class="l">@[</span><span class="s">@&quot;page1.jpg&quot;</span><span class="p">,</span> <span class="s">@&quot;page2.jpg&quot;</span><span class="p">,</span> <span class="s">@&quot;page3.jpg&quot;</span><span class="p">,</span> <span class="s">@&quot;page4.jpg&quot;</span><span class="l">]</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'>    <span class="c1">// Create page view controller</span>
</span><span class='line'>    <span class="nb">self</span><span class="p">.</span><span class="n">pageViewController</span> <span class="o">=</span> <span class="p">[</span><span class="nb">self</span><span class="p">.</span><span class="n">storyboard</span> <span class="nl">instantiateViewControllerWithIdentifier</span><span class="p">:</span><span class="s">@&quot;PageViewController&quot;</span><span class="p">];</span>
</span><span class='line'>    <span class="nb">self</span><span class="p">.</span><span class="n">pageViewController</span><span class="p">.</span><span class="n">dataSource</span> <span class="o">=</span> <span class="nb">self</span><span class="p">;</span>
</span><span class='line'>
</span><span class='line'>    <span class="n">PageContentViewController</span> <span class="o">*</span><span class="n">startingViewController</span> <span class="o">=</span> <span class="p">[</span><span class="nb">self</span> <span class="nl">viewControllerAtIndex</span><span class="p">:</span><span class="mi">0</span><span class="p">];</span>
</span><span class='line'>    <span class="bp">NSArray</span> <span class="o">*</span><span class="n">viewControllers</span> <span class="o">=</span> <span class="l">@[</span><span class="n">startingViewController</span><span class="l">]</span><span class="p">;</span>
</span><span class='line'>    <span class="p">[</span><span class="nb">self</span><span class="p">.</span><span class="n">pageViewController</span> <span class="nl">setViewControllers</span><span class="p">:</span><span class="n">viewControllers</span> <span class="nl">direction</span><span class="p">:</span><span class="n">UIPageViewControllerNavigationDirectionForward</span> <span class="nl">animated</span><span class="p">:</span><span class="nb">NO</span> <span class="nl">completion</span><span class="p">:</span><span class="nb">nil</span><span class="p">];</span>
</span><span class='line'>
</span><span class='line'>    <span class="c1">// Change the size of page view controller</span>
</span><span class='line'>    <span class="nb">self</span><span class="p">.</span><span class="n">pageViewController</span><span class="p">.</span><span class="n">view</span><span class="p">.</span><span class="n">frame</span> <span class="o">=</span> <span class="n">CGRectMake</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="nb">self</span><span class="p">.</span><span class="n">view</span><span class="p">.</span><span class="n">frame</span><span class="p">.</span><span class="n">size</span><span class="p">.</span><span class="n">width</span><span class="p">,</span> <span class="nb">self</span><span class="p">.</span><span class="n">view</span><span class="p">.</span><span class="n">frame</span><span class="p">.</span><span class="n">size</span><span class="p">.</span><span class="n">height</span><span class="o">-</span><span class="mi">30</span><span class="p">);</span>
</span><span class='line'>
</span><span class='line'>    <span class="p">[</span><span class="nb">self</span> <span class="nl">addChildViewController</span><span class="p">:</span><span class="n">_pageViewController</span><span class="p">];</span>
</span><span class='line'>    <span class="p">[</span><span class="nb">self</span><span class="p">.</span><span class="n">view</span> <span class="nl">addSubview</span><span class="p">:</span><span class="n">_pageViewController</span><span class="p">.</span><span class="n">view</span><span class="p">];</span>
</span><span class='line'>    <span class="p">[</span><span class="nb">self</span><span class="p">.</span><span class="n">pageViewController</span> <span class="nl">didMoveToParentViewController</span><span class="p">:</span><span class="nb">self</span><span class="p">];</span>
</span><span class='line'><span class="p">}</span>
</span></code></pre></td></tr></table></div></figure>


<h2>效果展示</h2>

<p><img src="/images/xiaoguo1.png" alt="效果图1" /> <img src="/images/xiaoguo2.png" alt="效果图2" /></p>

<h2>项目源码</h2>

<p><a href="https://github.com/Loongwoo/PageViewDemo">PageViewDemo代码下载</a></p>

<h2>参考链接</h2>

<ol>
<li><a href="http://www.cocoachina.com/ios/20141217/10669.html">http://www.cocoachina.com/ios/20141217/10669.html</a></li>
<li><a href="http://www.kyleduo.com/?p=278">http://www.kyleduo.com/?p=278</a></li>
</ol>

</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2015/07/06/at-ioszhong-propertyde-xiu-shi-zi/">IOS中Property的修饰字</a></h1>
    
    
      <p class="meta">
        




<time class='entry-date' datetime='2015-07-06T09:42:07+08:00'><span class='date'><span class='date-month'>Jul</span> <span class='date-day'>6</span><span class='date-suffix'>th</span>, <span class='date-year'>2015</span></span> <span class='time'>9:42 am</span></time>
        
      </p>
    
  </header>


  <div class="entry-content"><h2>assign、copy 、retain（MRC）</h2>

<ul>
<li>assign: 对基础数据类型 （NSInteger）和C数据类型（int, float, double, char,等）</li>
<li>copy：对NSString（不用同一块内存）</li>
<li>retain：对其他NSObject和其子类（用同一块内存）

<h2>readonly、readwrite</h2></li>
<li>readonly：只读</li>
<li><p>readwrite：读写（默认属性）</p>

<h2>weak、strong（ARC下避免循环引用需要申明weak指针）</h2>

<p><a href="http://www.2cto.com/kf/201409/332193.html">三种容易引起循环引用的场景</a></p></li>
<li><p>weak：指针指向的地址一旦被释放，这些指针都将被赋值为nil。这样的好处能有效的防止野指针。</p></li>
<li>strong：strong就相当于retain属性，而weak相当于assign<br />
<strong>具体一点：IBOutlet可以为weak，NSString为copy，delegate一般为weak，其他的看情况。一般来说，类“内部”的属性设置为strong，类“外部”的属性设置为weak。说到底就是一个归属权的问题。小心出现循环引用导致内存无法释放。</strong>

<h2>nonatomic、atomic</h2></li>
<li>nonatomic：不加同步，多线程并发访问会提高性能。</li>
<li>atomic：默认值<br />
了解<a href="http://www.parallellabs.com/2011/04/09/pthread-mutex-lock-and-thread-safety/">原子操作</a>，以及<a href="http://blog.csdn.net/cubepeng/article/details/7735962">非原子操作的效率提升</a>。</li>
</ul>


<h2>参考链接</h2>

<p>[<a href="http://www.aichengxu.com/view/32930">http://www.aichengxu.com/view/32930</a>]<br />
[<a href="http://www.2cto.com/kf/201205/133943.html">http://www.2cto.com/kf/201205/133943.html</a>]</p>
</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2015/07/05/at-iosshu-xing-he-cheng-yuan-bian-liang/">IOS属性和成员变量</a></h1>
    
    
      <p class="meta">
        




<time class='entry-date' datetime='2015-07-05T21:48:27+08:00'><span class='date'><span class='date-month'>Jul</span> <span class='date-day'>5</span><span class='date-suffix'>th</span>, <span class='date-year'>2015</span></span> <span class='time'>9:48 pm</span></time>
        
      </p>
    
  </header>


  <div class="entry-content"><p>接手IOS开发开始就是从项目入手，基础很薄弱。成员变量和属性的用法一向比较混乱，难得有空补点课。</p>

<h1>类（Class）中的成员变量和属性</h1>

<h2>相关文档</h2>

<p>英文文档 <a href="https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/ProgrammingWithObjectiveC/EncapsulatingData/EncapsulatingData.html">《The Objective-c Programming Language》</a><br />
中文文档 <a href="http://blog.csdn.net/column/details/object-c.html">Objective-C编程语言官方文档翻译</a></p>

<h2>关于@synthesize object =_object的解释</h2>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">@</span><span class="n">interface</span><span class="err"> </span><span class="nl">MyClass</span><span class="p">:</span><span class="bp">NSObject</span><span class="p">{</span>
</span><span class='line'>    <span class="n">MyObjecct</span><span class="err"> </span><span class="o">*</span><span class="n">_object</span><span class="p">;</span><span class="c1">//成员变量</span>
</span><span class='line'><span class="p">}</span>
</span><span class='line'><span class="k">@property</span><span class="p">(</span><span class="n">nonamtic</span><span class="p">,</span><span class="err"> </span><span class="k">retain</span><span class="p">)</span><span class="err"> </span><span class="n">MyObjecct</span><span class="err"> </span><span class="o">*</span><span class="n">object</span><span class="p">;</span><span class="c1">//属性property</span>
</span><span class='line'><span class="k">@end</span>
</span><span class='line'>
</span><span class='line'><span class="p">@</span><span class="n">implementatin</span><span class="err"> </span><span class="n">MyClass</span>
</span><span class='line'><span class="k">@synthesize</span><span class="err"> </span><span class="n">object</span><span class="o">=</span><span class="n">_object</span><span class="p">;</span>
</span><span class='line'><span class="k">@end</span>
</span></code></pre></td></tr></table></div></figure>


<p>synthesize定义了一对getter和setter方法，在这里的getter方法是object，setter方法是setObject，事实上getter和setter方法操作的是变量_object。属性通过点表达式(.)来访问其实是调用了getter和setter方法，其实就是操作了成员变量_object。故在.m文件中可以直接的使用_object实例变量，也可以通过属性self.object是一样的。<strong>简单来说，属性就是定义了getter和setter方法来操作_object成员变量</strong></p>

<h2>现在推荐的做法</h2>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="p">@</span><span class="n">interface</span><span class="err"> </span><span class="nl">MyClass</span><span class="p">:</span><span class="bp">NSObject</span>
</span><span class='line'><span class="k">@property</span><span class="p">(</span><span class="n">nonamtic</span><span class="p">,</span><span class="err"> </span><span class="k">retain</span><span class="p">)</span><span class="err"> </span><span class="n">MyObjecct</span><span class="err"> </span><span class="o">*</span><span class="n">object</span><span class="p">;</span><span class="c1">//属性</span>
</span><span class='line'><span class="k">@end</span>
</span></code></pre></td></tr></table></div></figure>


<p>编译器会自动生成_object、getter和setter方法。</p>

<ol>
<li>成员变量为该类变量私有，最好声明在implementation里</li>
<li>public的属性写在.h文件里</li>
<li>如果自己内部需要setter和getter来实现一些东西，就在.m文件的类目里用property来申明</li>
</ol>


<h1>类别（Category）中得属性</h1>

<p>类别（Category）：常常为了拓展类的功能会对类进行拓展。如</p>

<figure class='code'><figcaption><span></span></figcaption><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class='objectivec'><span class='line'><span class="k">@interface</span> <span class="bp">UIViewController</span> <span class="nl">(UINavigationControllerItem)</span>
</span><span class='line'><span class="k">@property</span><span class="p">(</span><span class="k">nonatomic</span><span class="p">,</span><span class="k">readonly</span><span class="p">,</span><span class="k">retain</span><span class="p">)</span> <span class="bp">UINavigationItem</span> <span class="o">*</span><span class="n">navigationItem</span><span class="p">;</span>
</span><span class='line'><span class="k">@property</span><span class="p">(</span><span class="k">nonatomic</span><span class="p">)</span> <span class="kt">BOOL</span> <span class="n">hidesBottomBarWhenPushed</span><span class="p">;</span>
</span><span class='line'><span class="k">@property</span><span class="p">(</span><span class="k">nonatomic</span><span class="p">,</span><span class="k">readonly</span><span class="p">,</span><span class="k">retain</span><span class="p">)</span> <span class="bp">UINavigationController</span> <span class="o">*</span><span class="n">navigationController</span><span class="p">;</span>
</span><span class='line'><span class="k">@end</span>
</span></code></pre></td></tr></table></div></figure>


<p>这里添加的属性，不会自动生成实例变量，这里添加的属性其实是添加的getter与setter方法。</p>

<h1>后记</h1>

<h2>下节预告</h2>

<p>下一篇可以梳理一下属性的nonatomic、retain、weak、strong的用法，以及类别中添加属性的方法。</p>

<h2>参考链接：</h2>

<p><a href="http://www.cnblogs.com/ygm900/p/3660364.html">http://www.cnblogs.com/ygm900/p/3660364.html</a></p>
</div>
  
  


    </article>
  
  
    <article>
      
  <header>
    
      <h1 class="entry-title"><a href="/blog/2015/07/05/at-qian-yan/">前言</a></h1>
    
    
      <p class="meta">
        




<time class='entry-date' datetime='2015-07-05T20:13:43+08:00'><span class='date'><span class='date-month'>Jul</span> <span class='date-day'>5</span><span class='date-suffix'>th</span>, <span class='date-year'>2015</span></span> <span class='time'>8:13 pm</span></time>
        
      </p>
    
  </header>


  <div class="entry-content"><h1>为什么开博客？</h1>

<p>毕业几年了，刚开始做C#的时候写过一些博客，当时做的时间不久，知识点都是一知半解的。然后又做了两年Android手机，用了Jave和C语言。去年才开始做IOS开发，做智能家居的创业公司，边学边开发，也没时间总结，前后做了3个APP，往往是刚做完就又开始下一个，其实都不忍心看刚刚才开发完成的这一个。</p>

<p>这一年里每每不懂了就来网上扒，也没个总结，只怕到时候还是什么都还回去了。今天弄了一个技术博客，希望自己能够坚持充电，也不断总结自己的知识点。</p>

<h1>这个技术博客怎么弄的？</h1>

<p>这个主要是参考了<a href="http://blog.leichunfeng.com">雷纯锋</a>和<a href="http://blog.devtang.com">唐巧</a>的几篇文章搞出来的，功能还很简单，有空了再完善一下。话说弄一个自己专属的博客可以让自己享受下DIY的乐趣，增加一些发博的动力，想起来也蛮好玩的。</p>

<h1>Markdown语法</h1>

<p>Markdown语言对文章排版非常方便，其实常用的就是分段，加链接、图片，几个符号就搞定了，发布出来就能看到效果，很方便实用。顺便记录一个网址，方便查询<a href="http://segmentfault.com/markdown">Markdown 编辑器语法指南</a></p>
</div>
  
  


    </article>
  
  <div class="pagination">
    
    <a href="/blog/archives">Blog Archives</a>
    
    <a class="next" href="/index.html">Newer &rarr;</a>
    
  </div>
</div>
<aside class="sidebar">
  
    <section>
  <h1>最新文章</h1>
  <ul id="recent_posts">
    
      <li class="post">
        <a href="/blog/2016/01/28/stringmanage-a-xcode-plugin-for-managing-your-strings/">StringManage -- a Xcode Plugin for Managing Your Strings</a>
      </li>
    
      <li class="post">
        <a href="/blog/2015/09/12/iosshi-yong-bundle/">iOS使用Bundle</a>
      </li>
    
      <li class="post">
        <a href="/blog/2015/09/12/iosduo-ge-localizable-dot-strings/">IOS多个Localizable.strings</a>
      </li>
    
      <li class="post">
        <a href="/blog/2015/09/11/iosxian-zhi-uitextfieldchang-du/">IOS限制UITextField长度</a>
      </li>
    
      <li class="post">
        <a href="/blog/2015/09/11/ioszi-dong-bu-ju-constraintswithvisualformat/">IOS自动布局constraintsWithVisualFormat</a>
      </li>
    
  </ul>
</section>




<section>
	<h1>关于我</h1>
    <p>程序员、创业者、IOS开发工程师
	<br/>新浪微博：<a href='http://weibo.com/loongwoo' target='_blank'>商陆_Xu</a>
	<br/>新浪博客：<a href="http://blog.sina.com.cn/lunaize" target="_blank" title="商陆的博客">商陆</a>
	<br/>GitHub：<a href='https://github.com/loongwoo' target='_blank'>Loongwoo</a>
	<br/>Git@OSC: <a href='http://git.oschina.net/redder_xu' target='_blank'>redder_xu</a>
    <br/>CSDN博客：<a href="http://blog.csdn.net/redder_xu" target="_blank" title="CSDN">霜叶红于二月花</a>
	<br/>个人微信：xulongwu77 欢迎调戏
	<br/><img width="220px" src="/images/myweixin.jpg" />
	</p>
</section>
<section>
  <h1>友情链接</h1>
  <ul>
  <li><a href="http://blog.devtang.com" target="_blank" title="唐巧的技术博客">唐巧的技术博客</a></li>
  <li><a href="http://www.leichunfeng.com" target="_blank" title="雷纯锋的技术博客">雷纯锋的技术博客</a></li>
  <li><a href="http://www.superqq.com" target="_blank" title=“刚刚在线”>刚刚在线</a></li>
  </ul>
</section>

  
</aside>

    </div>
  </div>
  <footer role="contentinfo"><p>
  Copyright &copy; 2017 - 许龙武 -
  <span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
  <script language="javascript" type="text/javascript" src="http://js.users.51.la/17858326.js"></script>
<noscript><a href="http://www.51.la/?17858326" target="_blank"><img alt="&#x6211;&#x8981;&#x5566;&#x514D;&#x8D39;&#x7EDF;&#x8BA1;" src="http://img.users.51.la/17858326.asp" style="border:none" /></a></noscript>

</p>

</footer>
  











</body>
</html>
